//
//  ToolView.m
//  QizAIDemo
//
//  Created by Mephisto on 2025/4/23.
//

#import "ToolView.h"
#import <Masonry/Masonry.h>
#import <QMUIKit/QMUIKit.h>

@interface ToolView ()

//@property(nonatomic, strong) UILabel *expandLableL;
@property(nonatomic, strong) UIStackView *stackV;
@property(nonatomic, strong) UIStackView *btnStackV;
@property(nonatomic, strong) UIStackView *hStackV;

@end

@implementation ToolView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView {
    [self addSubview:self.hStackV];
    [self.hStackV addArrangedSubview:self.stackV];
    [self.hStackV addArrangedSubview:self.btnStackV];

    [self.stackV addArrangedSubview:self.memeberIdTF];
    [self.stackV addArrangedSubview:self.accountNoTF];

    [self.btnStackV addArrangedSubview:self.sureBtn];
//    [self.btnStackV addArrangedSubview:self.updateBtn];

//    [self.hStackV addArrangedSubview:self.expandLableL];
//    [self.hStackV addArrangedSubview:self.expandSwitch];

    [self setupLayout];
}

- (void)setupLayout {
    [self.hStackV mas_makeConstraints:^(MASConstraintMaker *make) {
      make.edges.equalTo(self);
    }];

    [self.memeberIdTF mas_makeConstraints:^(MASConstraintMaker *make) {
      make.height.equalTo(@40);
    }];

    [self.accountNoTF mas_makeConstraints:^(MASConstraintMaker *make) {
      make.height.equalTo(@40);
    }];

    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
      make.height.equalTo(@40);
      make.width.equalTo(@60);
    }];

//    [self.updateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//      make.height.equalTo(@40);
//      make.width.equalTo(@60);
//    }];
//
//    [self.expandLableL mas_makeConstraints:^(MASConstraintMaker *make) {
//      make.width.equalTo(@60);
//    }];
}

#pragma mark - Lazy

- (UIStackView *)hStackV {
    if (_hStackV == nil) {
        UIStackView *stack = UIStackView.new;
        stack.axis = UILayoutConstraintAxisHorizontal;
        stack.alignment = UIStackViewAlignmentCenter;
        stack.layoutMarginsRelativeArrangement = true;
        stack.directionalLayoutMargins =
            NSDirectionalEdgeInsetsMake(0, 10, 0, 10);
        stack.spacing = 8;
        stack.insetsLayoutMarginsFromSafeArea = false;
        _hStackV = stack;
    }
    return _hStackV;
}

- (UIStackView *)stackV {
    if (_stackV == nil) {
        UIStackView *stack = UIStackView.new;
        stack.axis = UILayoutConstraintAxisVertical;
        stack.layoutMarginsRelativeArrangement = true;
        stack.layoutMargins = UIEdgeInsetsZero;
        stack.spacing = 8;
        _stackV = stack;
    }
    return _stackV;
}

- (UIStackView *)btnStackV {
    if (_btnStackV == nil) {
        UIStackView *stack = UIStackView.new;
        stack.axis = UILayoutConstraintAxisVertical;
        stack.layoutMarginsRelativeArrangement = true;
        stack.layoutMargins = UIEdgeInsetsZero;
        stack.spacing = 8;
        _btnStackV = stack;
    }
    return _btnStackV;
}

- (QMUITextField *)memeberIdTF {
    if (_accountNoTF == nil) {
        QMUITextField *textTF = QMUITextField.new;
        textTF.textInsets = UIEdgeInsetsMake(0, 10, 0, 10);
        textTF.font = [UIFont systemFontOfSize:12];
        textTF.textColor = UIColor.blackColor;
        textTF.placeholder = @"请输入MemeberId,必填";
        textTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        textTF.backgroundColor = UIColor.whiteColor;
        _memeberIdTF = textTF;
    }
    return _memeberIdTF;
}

- (QMUITextField *)accountNoTF {
    if (_accountNoTF == nil) {
        QMUITextField *textTF = QMUITextField.new;
        textTF.textInsets = UIEdgeInsetsMake(0, 10, 0, 10);
        textTF.font = [UIFont systemFontOfSize:12];
        textTF.textColor = UIColor.blackColor;
        textTF.placeholder = @"请输入AccountNo 非必填";
        textTF.clearButtonMode = UITextFieldViewModeWhileEditing;
        textTF.backgroundColor = UIColor.whiteColor;
        _accountNoTF = textTF;
    }
    return _accountNoTF;
}

- (UIButton *)sureBtn {
    if (_sureBtn == nil) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
        btn.titleLabel.font = [UIFont systemFontOfSize:12];
        btn.layer.cornerRadius = 8;
        btn.layer.masksToBounds = true;
        [btn setTitle:@"确定" forState:UIControlStateNormal];
        [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        btn.backgroundColor = UIColor.blueColor;
        _sureBtn = btn;
    }
    return _sureBtn;
}

//- (UIButton *)updateBtn {
//    if (_updateBtn == nil) {
//        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
//        btn.titleLabel.font = [UIFont systemFontOfSize:12];
//        btn.layer.cornerRadius = 8;
//        btn.layer.masksToBounds = true;
//        [btn setTitle:@"更新" forState:UIControlStateNormal];
//        [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
//        btn.backgroundColor = UIColor.blueColor;
//        _updateBtn = btn;
//    }
//    return _updateBtn;
//}
//
//- (UILabel *)expandLableL {
//    if (_expandLableL == nil) {
//        UILabel *label = UILabel.new;
//        label.font = [UIFont systemFontOfSize:12];
//        label.numberOfLines = 0;
//        label.qmui_lineHeight = 22;
//        label.textColor = UIColor.blackColor;
//        label.text = @"展开/收起";
//        _expandLableL = label;
//    }
//    return _expandLableL;
//}
//
//- (UISwitch *)expandSwitch {
//    if (_expandSwitch == nil) {
//        UISwitch *switchView = UISwitch.new;
//        switchView.on = true;
//        _expandSwitch = switchView;
//    }
//    return _expandSwitch;
//}

@end
